<!--
    Copyright 2010 Justin Lipton, Jonathan Rosenberg
    
    This file is part of MediaList.

    MediaList is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MediaList is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MediaList.  If not, see <http://www.gnu.org/licenses/>.
-->

<html>
    <head>
        <title>MediaList</title>
        <script type="text/javascript" src="profile.js"></script>
        <link rel="stylesheet" type="text/css" href="main.css" />
    </head>
    
    <body bgcolor=white>
        <div class=mainHeader>MediaList!</div>
        <div class=mainBody>

            <table width='942'>
            <tr height='220' valign='top'>
            <td width='200'>
            <?php
            $currentUser=$_GET["currentUser"];
            if(!file_exists('user_pictures/' . "$current_user" . '.jpg'))
            {
                echo "<img src='user_pictures/00.jpg' />";
            }
            else
            {
                echo '<img src = user_pictures/' . "$currentUser" . ".jpg width = '200' height = '200'/>";
            }
            if($_GET["currentUser"] == $_COOKIE["user"])
            {
                echo '<a href="javascript:editImage();"> Edit </a><br />';
            }
            ?>
            </td>
            <td width='371'>
            <?php
            
              echo '<b>' . $_GET["currentUser"] . '</b><br /><table>';
              
              $con = mysql_connect("localhost", "root");
              if (!$con)
              {
                  die('Could not connect: ' . mysql_error());
              }
              mysql_select_db("DB", $con);
              $sql="SELECT * FROM users WHERE Username = '".$_GET["currentUser"]. "'";
              $result = mysql_query($sql, $con);
              echo mysql_error();
              $row = mysql_fetch_array($result);
              
              echo '<tr><td>Gender: </td><td>';
              if($row["Gender"] == 'M')
              {
                  echo 'Male';
              }
              else
              {
                  echo 'Female';
              }
              echo '</td></tr>';
              
              list($date, $time) = explode(' ', $row["Birthday"]);
              list($year, $month, $day) = explode('-', $date);
              $timestamp = mktime($hour, $minute, $second, $month, $day, $year);          
              $d=date('F d, Y', $timestamp);
              echo '<tr><td>Birthday: </td><td>' . $d . '</td></tr>';
              
              echo '<tr><td>Location: </td><td>' . $row["Location"] . '</td></tr>';
              
              list($date, $time) = explode(' ', $row["JoinDay"]);
              list($year, $month, $day) = explode('-', $date);
              $timestamp = mktime($hour, $minute, $second, $month, $day, $year);          
              $d=date('F d, Y', $timestamp);
              echo '<tr><td>Join Date: </td><td>' . $d . '</td></tr>';
              
              echo '<tr><td>Forum Posts: </td><td>' . $row["NumForumPosts"] . '</td></tr>';

              echo '</table>';

              echo '</td><td width=\'371\'><br />';
              echo '<table>';
              echo '<tr><td>Total Watched: </td><td>' . $row["TotalTimeMinutes"] . '</td></tr>';
              echo '<tr><td>Watching: </td><td>' . $row["NumViewing"] . '</td></tr>';
              echo '<tr><td>Completed: </td><td>' . $row["NumCompleted"] . '</td></tr>';
              echo '<tr><td>Dropped: </td><td>' . $row["NumDropped"] . '</td></tr>';
              echo '<tr><td>Planning: </td><td>' . $row["NumPlanning"] . '</td></tr>';
              echo '</table>';
            ?>
            </td>
            </tr>
            
            <tr valign='top'>
            <td width='200' rowspan='2'>
            <b>Favorites</b><br />
            <?php
            if($_GET["currentUser"] == $_COOKIE["user"])
            {
                echo '<a href="javascript:editFavorites();"> Edit </a><br />';
            }
            ?>
            </td>
            <td colspan='2'>
            <b>About Me</b><br />
            <?php
            if($_GET["currentUser"] == $_COOKIE["user"])
            {
                echo '<a href="javascript:changeToEdit(\'' . $_GET["currentUser"] . '\');"> Edit </a><br />';
            }
            echo '<span id="aboutme">';
            echo '<span id="aboutmeerror"></span>';
            $file=fopen('user_profiles/' . $_GET["currentUser"] . '.txt',"r") or exit("Unable to open file!");
            while(!feof($file))
            {
                echo fgets($file). "<br />";
            }
            fclose($file);
            echo '</span>';
            ?>
            </td>
            </tr>
            <tr>
            <td colspan='2'>
            <b>Wall</b><br />
            place holder for wall
            </td>
            </table>
        </div>
        <br/>
        
        
        <?php
            $con = mysql_connect("localhost", "root");
            if (!$con)
            {
                die('Could not connect: ' . mysql_error());
            }
            mysql_select_db("DB", $con);
            
            $sql="SELECT user_to, compatibility FROM correlated_users WHERE 
            user_from = '".$_COOKIE["user"]."' ORDER BY compatibility DESC LIMIT 5";           
            
            $result = mysql_query($sql, $con);
            echo "Compatible People:<br/><table><tr>";
            echo mysql_error();
            while($row = mysql_fetch_array($result))
            {
                echo "<tr><td>".$row["user_to"]." ".$row["compatibility"]."</tr></td>";
            }
            echo "</tr></table>";
        ?>
    </body>
</html>